package com.captain.special.二叉树.中等;

/**
 * Des:
 * TODO 给定树 , 获取遍历的值
 * 给定值 ,还原树
 *
 * @author XL
 * @Date 2022/5/18 18:01
 */
public class 验证二叉树的前序序列化331 {
    int i = -1;
    int len;
    String[] arr;

    public boolean isValidSerialization(String preorder) {
        arr = preorder.split(",");
        len = arr.length;
        recur();
        return i == arr.length - 1;
    }

    public void recur() {
        i++;
        if (i >= len) return;
        if (arr[i].equals("#")) return;
        recur();
        recur();
    }
}
